def get_list(y):
    list_of_num = []
    num_1 = [i for i in y]
    dict_for_2_num = {"a":num_1[0], "b":num_1[1], "c":num_1[2], "d":num_1[3]}
    num_2 = [str(dict_for_2_num.get("a"))+str(dict_for_2_num.get("b")), str(dict_for_2_num.get("c"))+str(dict_for_2_num.get("d"))]
    cent = str(dict_for_2_num.get("b"))+str(dict_for_2_num.get("c"))
    num_3 =[str(dict_for_2_num.get("a"))+cent, cent+str(dict_for_2_num.get("d"))]
    list_of_num.extend(num_1)
    list_of_num.extend(num_2)
    list_of_num.extend(num_3)
    list_of_num.append(y)
    return list_of_num

def simple(y):
    list_a = []
    for i in range(2,y+1):
        a = y % i
        if a == 0:
            list_a.append(1)
        else:
            continue
    if len(list_a) == 1:
        return y
    else:
        return None


x = input()
if len(x) > 4 or len(x) < 4:
    print(0)
else:
    sim_nums = []
    list_of_sim_num = get_list(x)
    for i in list_of_sim_num:
        num = int(i)
        sim_num = simple(num)
        if sim_num != None:
            sim_nums.append(sim_num)
    if len(sim_nums) > 0:
        m = max(sim_nums)
        print(m)
    else:
        print(0)

